package com.wendy.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhuwending
 */
@Slf4j
public class DateUtil {

    public static Date convert2Date(String dateStr, String format) {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        Date date = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        try {
            date = dateFormat.parse(dateStr);
        } catch (ParseException e) {
            log.error("error", e);
        }
        return date;
    }

    public static String convert2String(Date date, String format) {
        if (null == date) {
            return null;
        }
        String s;
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        s = dateFormat.format(date);
        return s;
    }
}
